﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Retirement_myPolicy : System.Web.UI.Page
{
    public List<Policy> policies = new List<Policy>();
    protected void Page_Load(object sender, EventArgs e)
    {
        FundJob fundJob = new FundJob();
        fundJob.autoPayment();

        int custId = -1;

        if (Session["userID"] == null)
        {
            custId = 15369472;//TODO GET FROM SESSION

        }
        else
        {
            custId = Convert.ToInt32(Session["userID"]);
        }

       this.policies = Policy.getPolicy(custId);
       if (policies == null || policies.Count == 0)
       {
           return;
       }
       else
       {

           this.gv_alertList.DataSource = Alert.getAlerts(custId);
           this.gv_alertList.DataBind();


           this.gv_policyStatement.DataSource = policies;
           this.gv_policyStatement.DataBind();

       }

    }

    protected void gv_alertList_SelectedIndexChanged(object sender, EventArgs e)
    {

        int index = this.gv_alertList.SelectedIndex;

        if (index<0)
        {
            return;
        }

        HiddenField hdAlertId = this.gv_alertList.SelectedRow.FindControl("hd_alertId") as HiddenField;
        int id = int.Parse(hdAlertId.Value);
        Alert.confirm(id);

        //Alert alert = new Alert();
        //alert.confirm(id);
        //this.gv_alertList.DataSource = getData();
        //this.gv_alertList.DataBind();

        int custId = -1;

        if (Session["userID"] == null)
        {
            custId = 15369472;//TODO GET FROM SESSION

        }
        else
        {
            custId = Convert.ToInt32(Session["userID"]);

        }

        this.gv_alertList.DataSource = Alert.getAlerts(custId);
        this.gv_alertList.DataBind();

    }
    
    
    protected void gv_policyStatement_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
             String policyNo =this.gv_policyStatement.DataKeys[e.Row.RowIndex].Value.ToString();
            e.Row.Cells[0].Text = "Flexi Protect";

            decimal col2 = Convert.ToDecimal(e.Row.Cells[2].Text);
            e.Row.Cells[2].Text = col2.ToString("C");


            decimal col3 = Convert.ToDecimal(e.Row.Cells[3].Text);
            if (col3 == 0)
            {
                e.Row.Cells[3].Text = "NOT AVALABLE";
            }
            else
            {
                e.Row.Cells[3].Text = col3.ToString("C");
            }


            decimal col4 = Convert.ToDecimal(e.Row.Cells[4].Text);
            if (col4 == 0)
            {
                e.Row.Cells[4].Text = "NOT AVALABLE";
            }
            else
            {
                e.Row.Cells[4].Text = col4.ToString("C");
            }

            decimal totalPremiumPaid = Payment.getTotalPremiumPaid(policyNo);
            if (totalPremiumPaid != 0)
            {

                e.Row.Cells[5].Text = totalPremiumPaid.ToString("C");

            }
            else
            {
                e.Row.Cells[5].Text = "NIL";
            }
            
        }
    }
}